package com.kaibes.web.request;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class RequestBodyWrapper extends HttpServletRequestWrapper {

    private byte[] body;
    
    public RequestBodyWrapper(HttpServletRequest request, byte[] body) {
        super(request);
        this.body = body;
    }
    
    @Override
    public BufferedReader getReader() throws IOException {
        return new BufferedReader(new InputStreamReader(getInputStream(), getCharacterEncoding()));
    }

    @Override
    public ServletInputStream getInputStream() throws IOException {
        return new ByteServletInputStream(body);
    }

}
